export default class Song {
  constructor({id, mid, singer, name, album, duration, image, url}) {
    this.id = id
    this.mid = mid
    this.singer = singer
    this.name = name
    this.album = album
    this.duration = duration
    this.image = image
    this.url = url
  }
}

export function createSong(musicData) {
  return new Song({
    id: musicData.id,
    mid: musicData.mid,
    singer: getSinger(musicData.singer),
    name: musicData.name,
    album: musicData.album.name,
    duration: musicData.interval,
    image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.album.mid}.jpg?max_age=2592000`,
    url: musicData.url
  })
}

export function createSong1(musicData) {
  return new Song({
    id: musicData.songid,
    mid: musicData.songmid,
    singer: getSinger(musicData.singer),
    name: musicData.songname,
    album: musicData.albumname,
    duration: musicData.interval,
    image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`,
    url: musicData.url
  })
}

export function createMiguSong(musicData) {
  return new Song({
    id: musicData.id,
    mid: musicData.copyrightId,
    singer: musicData.singerName+"-咪咕",
    name: musicData.songName,
    album: musicData.albumName,
    duration: 300,
    image: musicData.cover,
    url: musicData.mp3
  })
}

function getSinger(singer){
  var ret = []
  if (!singer) {
    return ''
  }
  singer.forEach((item) => {
    ret.push(item.name)
  })
  return ret.join('/')
}